'use strict';

/**
 * @description 设备表模型
 * */
module.exports = app => {
  const { STRING, INTEGER } = app.Sequelize;

  const Device = app.model.define('device', {
    name: {
      type: STRING(20),
      allowNull: false,
      comment: '设备名',
    },
    parentId: {
      type: INTEGER,
      allowNull: true,
      comment: '父级id 0 为最大集',
    },
  });

  Device.associate = () => {
    app.model.Device.belongsTo(app.model.Device, {
      as: 'parentDevice',
      foreignKey: 'parentId',
    });
  };

  return Device;
};
